package com.sport.video.service.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import com.sport.video.cache.util.CacheUtil;
import com.sport.video.common.api.IUnifyApiService;
import com.sport.video.common.dto.bo.sys.SysUser;
import com.sport.video.common.dto.common.RequestParams;
import com.sport.video.common.dto.common.ResponseParams;
import com.sport.video.common.enums.RespEnum;
import com.sport.video.service.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 测试处理逻辑
 *@Author Gred
 *@Date 2019/3/1 10:49
 *@version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/")
public class UnifyController implements IUnifyApiService {

    @Resource
    private SysUserService sysUserService;
    @Resource
    private CacheUtil cacheUtil;

    @Override
    @PostMapping("/unifyApi")
    public ResponseParams unifyApi(RequestParams requestParam) {

        List<SysUser> users = sysUserService.list(MapUtil.newHashMap(1));
        ResponseParams response = new ResponseParams();

        cacheTest();

        response.setParam(users);
        response.setRespCode(RespEnum.SUCCESS.code);
        response.setRespMsg(RespEnum.SUCCESS.msg);
        response.setTimestamp(DateUtil.current(false));
        return response;
    }

    public void cacheTest() {
        String key = "cache";
        String value = "Hello world";
        cacheUtil.set(key, value);
        log.info("Cache result : " + cacheUtil.get(key));
    }
}
